package com.maple.callback.event.boot.listener;

import java.time.LocalTime;
import java.util.concurrent.TimeUnit;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.maple.callback.event.boot.User;
import com.maple.callback.event.boot.UserRegisterEvent;
import com.maple.callback.event.boot.service.UserService;

@Component
public class ManagerListener implements SmartApplicationListener {


	@Override
	@Async	
	public void onApplicationEvent(ApplicationEvent event) {
		LocalTime now = LocalTime.now();
		System.out.println(now+"我是管理员监听器，监听到了注册信息");
		try {
			TimeUnit.SECONDS.sleep(150);  //睡眠150s
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		UserRegisterEvent userRegisterEvent = (UserRegisterEvent)event;
		User user = userRegisterEvent.getUser();
		 now = LocalTime.now();
		System.out.println(now+"我是管理员监听器，监听到了注册信息，用户名："+user.getName()+"，密码："+user.getPassword());
		
	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return eventType == UserRegisterEvent.class;
	}

	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		
		return sourceType== UserService.class;
	}

}
